package com.example.photography.fragment;

import android.content.Intent;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.fastjson.JSON;
import com.example.photography.Activity.Store_Activity;
import com.example.photography.R;
import com.example.photography.adapter.store.StoreFragmentAdapter;
import com.example.photography.bean.StoreHomeBean;
import com.example.photography.common.AppNetConfig;
import com.example.photography.common.BaseFragment;
import com.example.photography.util.UIUtils;
import com.example.photography.util.Util;
import com.loopj.android.http.RequestParams;

import butterknife.BindView;

public class StoreFragment extends BaseFragment {

    //#e98f36
    @BindView(R.id.tv_search_home)
    TextView tvSearchHome;
    @BindView(R.id.iv_menu)
    ImageView ivMenu;
    @BindView(R.id.rv_home)
    RecyclerView rvHome;
    @BindView(R.id.ib_shoppingacar)
    ImageButton ibShoppingacar;

    @Override
    protected RequestParams getParams() {
        return null;
    }

    @Override
    protected String getUrl() {
//        return AppNetConfig.Store_HOME_URL;
        return null;
    }

    @Override
    protected void initData(String content) {
        //解析数据
        content = Util.getJson(getActivity(),"store_home.json");
        processData(content);
        initListen();

    }

    private void processData(String content) {
        StoreHomeBean storeHomeBean = JSON.parseObject(content,StoreHomeBean.class);
        StoreHomeBean.ResultBean result = storeHomeBean.getResult();
        if (result != null){//有数据
            //设置适配器
            StoreFragmentAdapter storeFragmentAdapter = new StoreFragmentAdapter(getActivity(),result);
            rvHome.setAdapter(storeFragmentAdapter);
            //设置布局管理者
            rvHome.setLayoutManager(new GridLayoutManager(getActivity(),1));
        }else {//没数据

        }

    }

    private void initListen() {
        ivMenu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity(), Store_Activity.class);
                startActivity(intent);
            }
        });

    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_store1;
    }
}


